//
//  NewHomeViewController.m
//  GC_OC
//
//  Created by  Quan He on 2022/4/8.
//



#import "NewHomeViewController.h"
#import "HomeService.h"
#import "NewHomeHeaderView.h"
#import "HomeMessageViewController.h"
#import "NewHomeTopChooseView.h"
#import "HomeBannerModel.h"
#import "CurriculumModel.h"
#import "NewHomeBannerCell.h"
#import "NewHomeInfoCell.h"
#import "NewHomeInfoHeaderView.h"
#import "NewHomeInfoFooterView.h"
#import "HomeButtonModel.h"
#import "NewHomeButtonTableViewCell.h"
#import "PlayViewController.h"
#import "PlayModel.h"
#import "PurchaseCarAnimationTool.h"
#import "MineViewController.h"


static NSString *const NewHomeInfoCellIdentifier = @"NewHomeInfoCell";

@interface NewHomeViewController ()<UITableViewDelegate, UITableViewDataSource, DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@property (nonatomic, strong)NSString* idString;

@property (nonatomic, strong) NewHomeHeaderView *headerView;
@property (nonatomic, strong) NewHomeTopChooseView *chooseView;
@property (nonatomic, strong) HomeService *service;
@property (nonatomic, strong) NSDictionary *data;
@property (nonatomic, strong) NSArray *chooseArr;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *tableData;
@property (nonatomic, strong) NSMutableArray *listDatas;
@property (nonatomic, assign) BOOL needRefresh;
@property (nonatomic, strong) NSMutableSet *hideSectionSet;
@property (nonatomic, strong) NSIndexPath *lastPath;
@property (nonatomic, strong) NSIndexPath *nextPath;

@property (nonatomic, strong) NSMutableArray *cacheList;

@end

@implementation NewHomeViewController
- (instancetype)initWithId:(NSString *)idString isHomePage:(BOOL)isHomePage{
    self = [super init];
    if (self) {
        self.isHomePage = isHomePage;
        self.idString = idString;
    }
    return self;
}

-(void)testClick{
 
    NSLog(@"[Cache shared].userInfo.userInfo.user_id~~>>%@",[Cache shared].user_id);
    
}

#pragma mark - Life
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess) name:@"loginSuccess" object:nil];
    [self initData];
    [self setupUI];
    [self networkObserver];
    [self requestData];
    [self reloadData];
    self.view.backgroundColor = AppMainColor;

    //从本地加载用户信息
    NSDictionary *info = [[NSUserDefaults standardUserDefaults] valueForKey:@"bnyt_userInfo"];
    if (info.count != 0) {
        NSError *err;
        UserModel *user = [[UserModel alloc] initWithDictionary:info error:&err];
        [Cache shared].userInfo = user;
        
    }
    
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"isSong"]) {
        NSString *fullName = @"savedSong.plist";
        NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:fullName];
        NSData *data = [NSData dataWithContentsOfFile:filePath];
        if (data) {
            NSDictionary *dic = [NSKeyedUnarchiver unarchiveObjectWithData:data];
            NSInteger songIndex = [dic[@"index"] integerValue];
            NSArray *songList = dic[@"arr"];
            NSString *playTime = dic[@"playtime"];
            NSString *playDuration = dic[@"playdura"];
            CGFloat songProgress = [dic[@"progress"] floatValue];
            CGFloat songRate = [dic[@"rate"] floatValue];
            
            if (songProgress > 0 && playDuration.floatValue > 0) {
                [SUPlayerManager manager].currentSongIndex = songIndex;
                [SUPlayerManager manager].songList = songList.mutableCopy;
                [SUPlayerManager manager].saveRate = songRate;
                
                CMTime changedTime = CMTimeMakeWithSeconds(playTime.floatValue, playDuration.floatValue);
                [SUPlayerManager manager].bottomView.circle.progress = songProgress;
                [[SUPlayerManager manager].player seekToTime:changedTime toleranceBefore:CMTimeMake(1, 10000) toleranceAfter:CMTimeMake(1, 10000) completionHandler:^(BOOL finished) {
                    [[SUPlayerManager manager] pausePlay];
                    [[SUPlayerManager manager].bottomView stopAnimating];
                }];
            }
        } else {
            NSLog(@"读取失败");
        }
    }
}

- (void)loginSuccess
{
    MineViewController *mine = [MineViewController new];
    mine.hidesBottomBarWhenPushed = YES;
    fkPushNav(mine);
}


- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.chooseView shouldHide:NO];
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    if (self.isHomePage) {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
    }else {
        [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
    

}





- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];

    [self.chooseView shouldHide:YES];
    [MBPlayerManager manager].currentPlayerHandle = nil;
    [MBPlayerManager manager].currentPlayer = nil;
    [MBPlayerManager manager].currentPlayModel = nil;
    
}


#pragma mark - UI
- (void)setupUI {
    // 头部
    if (self.isHomePage) {
        [self.view addSubview:self.headerView];
    }
    [self.view addSubview:self.chooseView];
    [self.chooseView setSuperView:self.view];
    
    // 列表
    [self.view addSubview:self.tableView];
}

- (void)setupLayout {
    
}

#pragma mark - Business
- (void)initData {
    self.chooseArr = [NSArray array];
    self.hideSectionSet = [NSMutableSet set];
    self.data = [self.service getHomeInfo:self.idString];
}

#pragma mark - Action
- (void)showMessageView {
    HomeMessageViewController* homeMessage=[[HomeMessageViewController alloc]init];
    CATransition* transition = [CATransition animation];
    transition.type = kCATransitionPush;//可更改为其他方式
    transition.subtype = kCATransitionFromLeft;//可更改为其他方式
    transition.duration = 0.25f;
    homeMessage.hidesBottomBarWhenPushed = YES;
    [self.navigationController.view.layer addAnimation:transition forKey:kCAOnOrderIn];
    [self.navigationController pushViewController:homeMessage animated:NO];
    if ([ICMusicPlayManager sharedManager].narrowView) {
        [ICMusicPlayManager sharedManager].narrowView.frame = CGRectMake(0, SCREEN_HEIGHT - 50 - HY_BottomWhiteBar_Height, SCREEN_WIDTH, 50);
    }
}

- (void)hideInfoWithSection:(NSInteger)section isHide:(BOOL)isHide{
    if (isHide) {
        [self.hideSectionSet addObject:[NSString stringWithFormat:@"%ld",section]];
    }else {
        [self.hideSectionSet removeObject:[NSString stringWithFormat:@"%ld",section]];
    }
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
}

#pragma mark - Request
- (void)networkObserver {
//    __weak typeof(self) weakSelf = self;
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == AFNetworkReachabilityStatusReachableViaWWAN || status == AFNetworkReachabilityStatusReachableViaWiFi) {
//            [weakSelf requestData];
        }
    }];
    [manager startMonitoring];
}

- (void)requestData {
    [self loadHotSearchInfoData];
    [self loadHomeInfoData];
}

- (void)reloadData {
    [self.hideSectionSet removeAllObjects];
    self.chooseView.infoArr = self.chooseArr;
    [self fillTheData];
}

//SearchView
- (void)loadHotSearchInfoData {
    __weak typeof(self) weakSelf = self;
    [self.service requestSearchInfo:^(NSArray * _Nonnull data) {
        [weakSelf.headerView.searchLabel setTextArray:data InteralTime:4.0 Direction:SHRollingDirectionUp];
    }];
}

//首页数据
- (void)loadHomeInfoData {
    __weak typeof(self) weakSelf = self;
    [self.service getHomeIdInfoWithIdString:self.idString finish:^(NSDictionary * _Nonnull data) {
        weakSelf.data = data;
        NSLog(@"首页\n%@",data);
        [weakSelf reloadData];
//        [weakSelf.tableView.mj_header endRefreshing];
    } error:^(NSError * _Nonnull error) {
        weakSelf.data = [weakSelf.service getHomeInfo:weakSelf.idString];
        [weakSelf reloadData];
//        [weakSelf.tableView.mj_header endRefreshing];
    }];
}

- (void)fillTheData {
    self.tableData = [[NSMutableArray alloc] init];
    _listDatas = NSMutableArray.array;
    if (self.data.count == 0) {
        return;
    }
    NSDictionary *data = self.data[@"data"];
    if (!data || [data isEqual:[NSNull null]]) return;
//    NSLog(@"%@",data);
    //Banner1
    NSMutableArray *firstBannerInfo = data[@"rotation_1"];
    if (!firstBannerInfo.isNullObject) {
        NSMutableArray *firstBanner = [[NSMutableArray alloc] init];
        for (NSDictionary *dic in firstBannerInfo) {
            [firstBanner addObject:[[HomeBannerModel alloc] initWithDic:dic]];
        }
        [self.tableData addObject:firstBanner];
        [_listDatas addObject:firstBannerInfo];
    }
    
    //标签按钮
    NSMutableArray *buttonInfo = data[@"media_class"];
    if (!buttonInfo.isNullObject) {
        NSMutableArray *buttonArr = [[NSMutableArray alloc] init];
        for (NSDictionary *dic in buttonInfo.reverseObjectEnumerator) {
            [buttonArr addObject:[[HomeButtonModel alloc] initWithDic:dic]];
        }
        if (buttonArr.count != 0) {
            [self.tableData addObject:buttonArr];
            [_listDatas addObject:buttonInfo];
            [self.hideSectionSet addObject:[NSString stringWithFormat:@"%ld",self.tableData.count - 1]];
        }
    }
    
    //cell
    NSDictionary *topInfo = data[@"top"];
    if (!topInfo.isNullObject) {
        NewHomeSectionModel *topModel = [[NewHomeSectionModel alloc] initWithDic:topInfo];
        if (!topModel.content.isNullObject) {
            [self.tableData addObject:topModel];
            [_listDatas addObject:topInfo];
        }
    }
    
    //Banner2
    NSMutableArray *secondBannerInfo = data[@"rotation_2"];
    if (!secondBannerInfo.isNullObject) {
        NSMutableArray *secondBanner = [[NSMutableArray alloc] init];
        for (NSDictionary *dic in secondBannerInfo) {
            [secondBanner addObject:[[HomeBannerModel alloc] initWithDic:dic]];
        }
        [self.tableData addObject:secondBanner];
        [_listDatas addObject:secondBannerInfo];
    }

    //cell2
    NSMutableArray *bottomInfo = data[@"bottom"];
//    NSLog(@"bottomInfo~~~>>%@",bottomInfo);
    if (!bottomInfo.isNullObject) {
        if (bottomInfo.count >= 1) {
            NewHomeSectionModel *secondSectionModel = [[NewHomeSectionModel alloc] initWithDic:bottomInfo.firstObject];
            if (!secondSectionModel.content.isNullObject) {
                [self.tableData addObject:secondSectionModel];
                BOOL isyoulike = NO;
                for (NSDictionary *dic in bottomInfo) {
                    if ([[NSString setSafeString:dic[@"tile"]] isEqualToString:@"猜你喜欢"]) {
                        isyoulike = YES;
                        [_listDatas addObject:dic];
                    }
                }
                if (!isyoulike) {
                    [_listDatas addObject:bottomInfo[0]];
                }
            }
        }
    }
    
    //Banner3
    NSMutableArray *thirdBannerInfo = data[@"rotation_3"];
    if (!thirdBannerInfo.isNullObject) {
        NSMutableArray *thirdBanner = [[NSMutableArray alloc] init];
        for (NSDictionary *dic in thirdBannerInfo) {
            [thirdBanner addObject:[[HomeBannerModel alloc] initWithDic:dic]];
        }
        [self.tableData addObject:thirdBanner];
        [_listDatas addObject:thirdBannerInfo];
    }

    //cell3
    if (!bottomInfo.isNullObject) {
        if (bottomInfo.count >= 2) {
            NewHomeSectionModel *lastSectionModel = [[NewHomeSectionModel alloc] initWithDic:bottomInfo[1]];
            if (!lastSectionModel.content.isNullObject) {
                [self.tableData addObject:lastSectionModel];
                [_listDatas addObject:bottomInfo[1]];
            }
        }
    }
    
    //Banner4
    NSMutableArray *fourthBannerInfo = data[@"rotation_4"];
    if (!fourthBannerInfo.isNullObject) {
        NSMutableArray *fourthBanner = [[NSMutableArray alloc] init];
        for (NSDictionary *dic in fourthBannerInfo) {
            [fourthBanner addObject:[[HomeBannerModel alloc] initWithDic:dic]];
        }
        [self.tableData addObject:fourthBanner];
        [_listDatas addObject:fourthBannerInfo];
    }
    
    //cell4
    if (!bottomInfo.isNullObject) {
        if (bottomInfo.count > 2) {
            for (int i = 2; i < bottomInfo.count; i ++) {
                NewHomeSectionModel *lastSectionModel = [[NewHomeSectionModel alloc] initWithDic:bottomInfo[i]];
                if (!lastSectionModel.content.isNullObject) {
                    [self.tableData addObject:lastSectionModel];
                    [_listDatas addObject:bottomInfo[i]];
                }
            }
        }
    }
    
    self.needRefresh = YES;
    [self.tableView reloadData];
    self.needRefresh = NO;
    CGFloat contentHeight = (self.chooseView.infoArr.count != 0) ? 46 : 0;
    if (self.isHomePage) {
        self.tableView.frame = CGRectMake(0, StatusBarHeight + 60 + contentHeight, SCREEN_WIDTH, SCREEN_HEIGHT - StatusBarHeight - 60 - GCtabbarHeight - contentHeight);
    }else {
        self.tableView.frame = CGRectMake(0, contentHeight, SCREEN_WIDTH, SCREEN_HEIGHT - topHeight - contentHeight);
    }
}

#pragma mark - Setter
- (void)setData:(NSDictionary *)data {
    _data = data;
    if (data.count != 0) {
        NSDictionary *data = self.data[@"data"];
        if (data  && ![data isKindOfClass:[NSNull class]]) {
            self.chooseArr = data[@"lable"];
        }
//        self.chooseArr = self.data[@"data"][@"lable"];
    }
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
    return self.tableData.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if ([self.tableData[section] isKindOfClass:[NewHomeSectionModel class]]) {
        NewHomeSectionModel *model = self.tableData[section];
        return model.content.count;
    }
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.tableData[indexPath.section] isKindOfClass:[NewHomeSectionModel class]]) {
        if ([self.hideSectionSet containsObject:[NSString stringWithFormat:@"%ld",indexPath.section]]) {
            return 0;
        }
        return 78;
    }else {
        NSMutableArray *array = self.tableData[indexPath.section];
        NSInteger modelCount = array.count;
        if ([array.firstObject isKindOfClass:[HomeButtonModel class]]) {
            NSInteger line = 1;
            if (modelCount <= 4) {
                line = 1;
            }else if (modelCount <= 8) {
                line = 2;
            }else {
                if ([self.hideSectionSet containsObject:[NSString stringWithFormat:@"%ld",indexPath.section]]) {
                    line = 2;
                }else {
                    line = ((modelCount + 1) / 4 + ((modelCount + 1) % 4 == 0 ? 0 : 1));
                }
            }
            return (36 + 12) * line + 8;
        }else {
            return 140 + 20;
        }
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if ([self.tableData[section] isKindOfClass:[NewHomeSectionModel class]]) {
//        return 38;
        return 1;
    }
    return 0.01;
}



- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if ([self.tableData[section] isKindOfClass:[NewHomeSectionModel class]]) {
        NewHomeInfoFooterView *footer = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([NewHomeInfoFooterView class])];
        if (!footer) {
            footer = [[NewHomeInfoFooterView alloc]initWithReuseIdentifier:NSStringFromClass([NewHomeInfoFooterView class])];
        }
        return footer;
    }
    return [[UIView alloc] init];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if ([self.tableData[section] isKindOfClass:[NewHomeSectionModel class]]) {
        return 62;
    }
    return 0.01;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if ([self.tableData[section] isKindOfClass:[NewHomeSectionModel class]]) {
        NewHomeSectionModel *model = self.tableData[section];
        NewHomeInfoHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([NewHomeInfoHeaderView class])];
        
        if (!header) {
            header = [[NewHomeInfoHeaderView alloc]initWithReuseIdentifier:NSStringFromClass([NewHomeInfoHeaderView class])];
        }
        header.titleLabel.text = model.title;
        __weak typeof(self) weakSelf = self;
        header.hide = [self.hideSectionSet containsObject:[NSString stringWithFormat:@"%ld",section]];
        header.hideAction = ^(BOOL isHide) {
            [weakSelf hideInfoWithSection:section isHide:isHide];
        };
        return header;
    }
    return [[UIView alloc] init];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.tableData[indexPath.section] isKindOfClass:[NewHomeSectionModel class]]) {
        NewHomeInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:NewHomeInfoCellIdentifier];
        if (!cell) {
            cell = [[NewHomeInfoCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:NewHomeInfoCellIdentifier];
        }
//        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:245/255.0 green:251/255.0 blue:1 alpha:1];
//        cell.backgroundColor = [UIColor redColor];
        NewHomeSectionModel *model = self.tableData[indexPath.section];
        cell.model = model.content[indexPath.row];
        return cell;
    }else {
        NSMutableArray *array = self.tableData[indexPath.section];
        if ([array.firstObject isKindOfClass:[HomeButtonModel class]]) {
            NSString *reuseIdentifier = [NSString stringWithFormat:@"NewHomeButtonTableViewCell%ld",(long)indexPath.section];
            NewHomeButtonTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
            
            if (!cell) {
                cell = [[NewHomeButtonTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
                [cell fillTheData:array];
            }
            __weak typeof(self) weakSelf = self;
            BOOL hide = [self.hideSectionSet containsObject:[NSString stringWithFormat:@"%ld",indexPath.section]];
            cell.hide = hide;
            cell.classId = self.idString;
            cell.hideAction = ^(BOOL isHide) {
                [weakSelf hideInfoWithSection:indexPath.section isHide:isHide];
            };
            cell.chooseAction = ^(NSInteger index) {

            };
            return cell;
        }else {
            NSString *reuseIdentifier = [NSString stringWithFormat:@"NewHomeBannerCell%ld",(long)indexPath.section];
            NewHomeBannerCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
            if (!cell) {
                cell = [[NewHomeBannerCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
                cell.dataArr = array;
            }
            if (self.needRefresh) {
                cell.dataArr = array;
            }
            return cell;
        }
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    __weak typeof(self) weakSelf = self;
    if ([self.tableData[indexPath.section] isKindOfClass:[NewHomeSectionModel class]]) {
        
        _lastPath = indexPath;
        
        for (int i = 0 ; i < self.tableData.count; i++) {
            if ([self.tableData[i] isKindOfClass:[NewHomeSectionModel class]]) {
                NewHomeSectionModel *jk1 = self.tableData[i];
                for (CurriculumModel *jk11 in jk1.content) {
                    jk11.isShow = NO;
                }
            }
        }
        
        NewHomeSectionModel *sectionModel = self.tableData[indexPath.section];
        CurriculumModel *cellModel = sectionModel.content[indexPath.row];
        cellModel.sectionTitle = sectionModel.title;
        cellModel.isShow = YES;
        [tableView reloadData];
        
        BOOL isCache = NO;
        NSInteger indexNum1 = 0;
        for (int i = 0; i < self.cacheList.count; i++) {
            NSDictionary *d = self.cacheList[i];
            NSString *did = [NSString stringWithFormat:@"%@", d[@"id"]];
            if ([did isEqualToString:cellModel.id]) {
                indexNum1 = i;
                isCache = YES;
                break;
            }
        }
        
        if (isCache) {
            [SUPlayerManager manager].currentSongIndex = indexNum1;
            [SUPlayerManager manager].songList = self.cacheList;
        } else {
            self.tableView.userInteractionEnabled = NO;
            [[[ObjectAFNetWorking alloc]init] getUrlStr:[NSString stringWithFormat:@"%@/api/home/getcatelist?id=%@",server_addr, cellModel.pid] finish:^(id  _Nonnull dataString) {

                NSDictionary* dic=[NSJSONSerialization JSONObjectWithData:dataString options:NSJSONReadingMutableContainers error:nil];
                NSArray *asss = dic[@"data"][@"list"];
                NSInteger indexNum = 0;
                for (int i = 0; i < asss.count; i++) {
                    NSDictionary *d = asss[i];
                    NSString *did = [NSString stringWithFormat:@"%@", d[@"id"]];
                    if ([did isEqualToString:cellModel.id]) {
                        indexNum = i;
                        break;
                    }
                }
                
                if (!((indexNum == [SUPlayerManager manager].currentSongIndex) && [asss isEqualToArray:[SUPlayerManager manager].songList])) {
                    [SUPlayerManager manager].currentSongIndex = indexNum;
                    [SUPlayerManager manager].songList = asss.mutableCopy;
                    self.cacheList = asss.mutableCopy;
                }
                self.tableView.userInteractionEnabled = YES;
            } andError:^(NSError * _Nonnull error) {
                self.tableView.userInteractionEnabled = YES;
            }];
        }
        
  
        
        NewHomeInfoCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
        UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yinfu"]];
        CGPoint fromCenter =  [cell.coverImageView convertPoint:CGPointMake(cell.coverImageView.frame.size.width * 0.5f, cell.coverImageView.frame.size.height * 0.5f) toView:keyWindow];
        imageV.center = fromCenter;
        imageV.size = CGSizeMake(18, 22);
        
        [[PurchaseCarAnimationTool shareTool] startAnimationandView:imageV
                                                               rect:imageV.frame
                                                        finisnPoint:CGPointMake(ScreenWidth / 4 * 2.5, SCREEN_HEIGHT - GCtabbarHeight -  50)
                                                        finishBlock:^(BOOL finish) {}];
        
        _nextPath = indexPath;
    }
}


#pragma mark DZNEmptyDataSetDelegate & DZNEmptyDataSetSource
- (void)emptyDataSet:(UIScrollView *)scrollView didTapView:(UIView *)view {
    [self requestData];
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView{
    return YES;
}

- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView{
    NSString *text = @"暂无内容，点击刷新";
    NSDictionary *attributes = @{
                                 NSFontAttributeName: [UIFont systemFontOfSize:15 weight:UIFontWeightRegular],
                                 NSForegroundColorAttributeName: [UIColor grayColor]};
    return [[NSAttributedString alloc] initWithString:text attributes:attributes];
}

#pragma mark - LazyLoad
- (HomeService *)service {
    if (!_service) {
        _service = [[HomeService alloc] init];
    }
    return _service;
}

- (NewHomeHeaderView *)headerView {
    if (!_headerView) {
        _headerView = [[NewHomeHeaderView alloc] initWithFrame:CGRectMake(0, StatusBarHeight, SCREEN_WIDTH, 60)];
        _headerView.searchID = self.idString;
        __weak typeof(self) weakSelf = self;
        _headerView.messageAction = ^{
            [weakSelf showMessageView];
        };
    }
    return _headerView;
}

- (NewHomeTopChooseView *)chooseView {
    if (!_chooseView) {
        if (self.isHomePage) {
            _chooseView = [[NewHomeTopChooseView alloc] initWithFrame:CGRectMake(0, StatusBarHeight + 60, SCREEN_WIDTH, 46)];
        }else {
            _chooseView = [[NewHomeTopChooseView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 46)];
        }
        _chooseView.classId = self.idString;
    }
    return _chooseView;
}

- (UITableView *)tableView {
    if (!_tableView) {
        if (self.isHomePage) {
            _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, StatusBarHeight + 106, SCREEN_WIDTH, SCREEN_HEIGHT - StatusBarHeight - 106 - GCtabbarHeight) style:UITableViewStyleGrouped];
        }else {
            _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 46, SCREEN_WIDTH, SCREEN_HEIGHT - topHeight - 46) style:UITableViewStyleGrouped];
        }
        if (@available(iOS 15.0, *)) {
            _tableView.sectionHeaderTopPadding = 0;
        }
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.emptyDataSetSource = self;
        _tableView.emptyDataSetDelegate = self;
        [_tableView registerClass:[NewHomeBannerCell class] forCellReuseIdentifier:NSStringFromClass([NewHomeBannerCell class])];
        UINib *lib = [UINib nibWithNibName:NewHomeInfoCellIdentifier bundle:nil];
        [_tableView registerNib:lib forCellReuseIdentifier:NewHomeInfoCellIdentifier];
        [_tableView registerClass:[NewHomeInfoHeaderView class] forHeaderFooterViewReuseIdentifier:NSStringFromClass([NewHomeInfoHeaderView class])];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerClass:[NewHomeButtonTableViewCell class] forCellReuseIdentifier:NSStringFromClass([NewHomeButtonTableViewCell class])];
        _tableView.backgroundColor = self.view.backgroundColor;
//        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(requestData)];
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
        _tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_HEIGHT, 60)];
    }
    return _tableView;
}


@end
